<?php
namespace Admin\Controller;

use Admin\Controller\GlobalController;

class RecordController extends GlobalController
{
    //杂志列表
    public function getlist()
    {
        $pageSize = 20;
        $where = array();
        $user_id = I('get.user_id', 0, 'intval');
        if (!empty($user_id)) {
            $where['user_id'] = $user_id;
        }
        $this->assign('user_id', $user_id == 0 ? '' : $user_id);
        $egg_id = I('get.egg_id', 0, 'intval');
        if (!empty($egg_id)) {
            $where['egg_id'] = $egg_id;
        }
        $this->assign('egg_id', $egg_id == 0 ? '' : $egg_id);
        $recordModel = M('smash_record');
        $count = $recordModel->where($where)->count();
        $pageObj = new \Admin\Util\Page($count, $pageSize);
        $list = $recordModel->where($where)->order('record_id desc')->limit($pageObj->firstRow . ',' . $pageObj->listRows)->select();
        $userModel = M('user');
        $eggModel = M('egg');
        foreach ($list as $key => $row) {
            $userInfo = $userModel->where(array('user_id' => $row['user_id']))->find();
            $eggInfo = $eggModel->where(array('egg_id' => $row['egg_id']))->find();
            $list[$key]['username'] = $userInfo['username'];
            $list[$key]['nickname'] = $userInfo['nickname'];
            $list[$key]['row_number'] = $eggInfo['row_number'];
            $list[$key]['egg_name'] = $eggInfo['egg_name'];
        }
        $this->assign('list', $list);
        $this->assign('page', $pageObj->show());
        $this->display();
    }

    //添加或者修改
    public function save()
    {
        $this->display();
    }
}